<template>
	<view class="home">
		<cmd-nav-bar :fixed="true" back left-text="宠物中心" right-text="添加" @rightText="addcore" title="" font-color="black"
		 background-color="#ffffff"></cmd-nav-bar>
		<view class="mo_ban"></view>
		<view class="pets_content" v-for="(item,index) in dataval" :style="{backgroundImage:backgroundfn(item.dog_nickname)}" @click="toinfo(index,item)">
			<view class="pets_inside">
				<image class="pets_head" ref='images' :src="images(item.dog_nickname)" mode=""></image>
				<view class="pets_name">{{item.dog_nickname}}</view>
				<view class="pets_text_">
					<text>{{item.dog_variety}}</text>|<text>{{dogage(item.dog_age)}}岁</text>|<text>{{item.dog_sex}}</text>
				</view>
				<view class="pets_Label">
					<text :class="item.updated_at">{{DogState(item,item.dog_state)}}</text>
					<!-- <text v-for="ba in item.bag" :class="ba.ClSuccess">{{item}}</text> -->
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import cmdNavBar from "@/components/cmd-nav-bar/cmd-nav-bar.vue"
	import dog_7 from '@/static/dog/7.jpg'
	import dog_6 from '@/static/dog/6.jpg'
	import dog_5 from '@/static/dog/5.jpg'
	export default {
		props: {},
		components: {
			cmdNavBar
		},
		data() {
			return {
				ClSuccess: 'clno', 
				backimg: 'url(' + dog_7 + ')',
				dataval:[],
				dataimage:[],
			}
		},
		methods: {
			DogState(item,val){
				switch(val){
					case '1':
					item.updated_at = 'clno';
					return '未认证';
					break;
					case '2':
					return '认证';
					item.updated_at = 'clok';
					break;
				}
			},
			addcore() { //添加
				uni.navigateTo({
					"url": '../service/bidfor/bidtwo',
				});
			},
			toinfo(index,val) {  //进入详情
			val.url = this.$refs.images[index].realImagePath
			val.backimgs =  'url(' + this.$refs.images[index].realImagePath + ')'
				uni.navigateTo({
					"url": '../mypage/le_assembly/doginfo?val='+JSON.stringify(val),
				});
			},
			GETPETDOG(){ //获取我的宠物
				this.$apifn.GetMyDog({}).then((res)=>{
					 if(res.data.Response.code == 200){
						 this.dataval = res.data.Response.data[0].user_dog;
					 }
				 }).catch((ret)=>{ 
					  
				});
			},
			dogage(val){ // 获得几岁
				return this.$oneselfFn.GetAge(val)
			},
			GET_IMG() { // 获取所有图片
			  this.$imgFn.seend({ 'path': this.$ENV.TRACING + this.$ENV.USER + uni.getStorageSync('USERINFO').id +'/'+ this.$ENV.PETAVATAR }).select(
			    (ref) => {
			      if (ref.status == 200) {
			        if (ref.data != {}) {
						this.dataimage = ref.data;
			        }
			      }
			    }, (res) => {
			      // console.log(res)
			    })
			},
			images(val){
				let image = '';
				this.dataimage.forEach((item)=>{
					if(val == item.split('/')[4]){
						image = item;
					}
				})
				return this.$ENV.UPLOADIMG+image;
			},
			backgroundfn(val){
				let image = '';
				this.dataimage.forEach((item)=>{
					if(val == item.split('/')[4]){
						image = item;
					}
				})
				return 'url(' + this.$ENV.UPLOADIMG+image + ')';
			}
		},
		watch: {},

		onReachBottom() { //页面上拉触底事件的处理函数

		},
		onPullDownRefresh() { //监听用户下拉动作，一般用于下拉刷新
			//需要在 pages.json 里，找到的当前页面的pages节点，并在 style 选项中开启 enablePullDownRefresh
			//uni.startPullDownRefresh(); 开启
			// uni.stopPullDownRefresh(); 关闭
		},
		onUnload() { //监听页面卸载

		},
		onHide() { //监听页面隐藏

		},
		onLoad() { // 替代 created 监听页面加载，其参数为上个页面传递的数据，参数类型为Object（用于页面传参），参考示例

		},
		created() {
			this.GET_IMG();
			this.GETPETDOG();
		},
		onReady() { //替代 mounted 监听页面初次渲染完成
		 // this.$oneselfFn.GetAge('2013-1-12');
		},

		onShow() { //监听页面显示
			//生命周期
		}
	}
</script>
<style lang="scss" scoped>
	.home {
		width: 100%;
		height: 100%;
	}

	.pets_content {
		width: 90%;
		height: 300upx;
		border-radius: 16upx;
		border: 1px solid #F4F5F6;
		margin: 40upx auto auto auto;
		background-size:100% 100%;
		// 		 -webkit-filter: blur(1px); /* Chrome, Safari, Opera */
		//     filter: blur(1px);

		.pets_inside {
			width: 80%;
			height: 200upx;
			border-radius: 16upx;
			margin: 40upx auto auto auto;
			// border: 1px solid #181818;
			background: #ffffffe8;

			.pets_head {
				width: 80upx;
				height: 80upx;
				border-radius: 50%;
				position: relative;
				top: -35upx;
				left: 42%;
			}

			.pets_name {
				width: 100%;
				height: 40upx;
				line-height: 40upx;
				text-align: center;
				font-weight: bolder;
				position: relative;
				top: -19px;
			}

			.pets_text_ {
				width: 70%;
				height: 40upx;
				margin: auto;
				display: flex;
				position: relative;
				top: -19px;
				font-size: 11px;
				color: #737373;

				text {
					width: 33%;
					height: 100%;
					text-align: center;
				}
			}

			.pets_Label {
				position: relative;
				top: -12px;
				width: 70%;
				height: 40upx;
				margin: auto;
				display: flex;

				.clok {
					width: 30%;
					height: 100%;
					border-radius: 10upx;
					background: #40c8ff;
					text-align: center;
					line-height: 40upx;
					font-size: 11px;
					color: #ffffff;
					margin-left: 3%;
				}

				.clno {
					width: 30%;
					height: 100%;
					border-radius: 10upx;
					background: #bdbdbd;
					text-align: center;
					line-height: 40upx;
					font-size: 11px;
					color: #8c8c8c;
					margin-left: 3%;
				}
			}
		}
	}

	.mo_ban {
		width: 100%;
		height: 92upx;
	}
</style>
